package com.quanxiaoha.weblog.admin.controller;

import com.quanxiaoha.weblog.admin.model.vo.messagewall.DeleteMessageWallReqVO;
import com.quanxiaoha.weblog.admin.model.vo.messagewall.QueryMessageWallPageListReqVO;
import com.quanxiaoha.weblog.admin.model.vo.messagewall.UpdateMessageWallStatusReqVO;
import com.quanxiaoha.weblog.admin.service.AdminMessageWallService;
import com.quanxiaoha.weblog.common.Response;
import com.quanxiaoha.weblog.common.aspect.ApiOperationLog;
import com.quanxiaoha.weblog.common.PageResponse;
import com.quanxiaoha.weblog.common.domain.dos.MessageWallDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/message-wall")
public class AdminMessageWallController {

    @Autowired
    private AdminMessageWallService messageWallService;

    @PostMapping("/list")
    @ApiOperationLog(description = "获取留言分页列表")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public PageResponse<MessageWallDO> getMessagePageList(@RequestBody QueryMessageWallPageListReqVO queryMessageWallPageListReqVO) {
        return messageWallService.getMessagePageList(queryMessageWallPageListReqVO);
    }

    @PostMapping("/update-status")
    @ApiOperationLog(description = "更新留言状态")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response updateMessageStatus(@RequestBody @Validated UpdateMessageWallStatusReqVO updateMessageWallStatusReqVO) {
        return messageWallService.updateMessageWallStatus(updateMessageWallStatusReqVO);
    }

    @PostMapping("/delete")
    @ApiOperationLog(description = "删除留言")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response deleteMessage(@RequestBody @Validated DeleteMessageWallReqVO deleteMessageWallReqVO) {
        return messageWallService.deleteMessageWall(deleteMessageWallReqVO);
    }
}